#ifndef _FONT_PIX_H_
#define _FONT_PIX_H_

#include <ft2build.h>
#include FT_FREETYPE_H

#include "../common/com_mem.h"

class CFontPix
{
private:
	typedef struct
	{
		int width,height;
		int advanceX, advanceY;
		int coordX, coordY;
		unsigned char *data;
	}TCharData;

	static const int FIRST_CHAR = 32;
	static const int LAST_CHAR = 128;
	static const int MAX_COLORS = 8;

	TCharData m_charData[LAST_CHAR-FIRST_CHAR];

	char *m_tempBuf;
	bool m_fontLoaded;
	int m_currentX, m_currentY;

	float m_colors[MAX_COLORS][4];
	void killFont();
public:
	static const int ALIGN_LEFT = -1;
	static const int ALIGN_CENTER = 0;
	static const int ALIGN_RIGHT = 1;
	static const int FORMAT_COLOR = 0xa0;

	CFontPix();
	~CFontPix();

	bool load(char *fname, int fontSize);
	bool load(void *data, int dataSize, int fontSize);

	void startRender(int width, int height);
	void endRender();

	void setColor(int color);
	void setColor3f(float red, float green, float blue);
	void setColor4f(float red, float green, float blue, float alpha);
	void setColor3fc(int color, float red, float green, float blue);
	void setColor4fc(int color, float red, float green, float blue, float alpha);

	void moveTo(int x, int y);
	void moveRel(int x, int y);

	void print(char *str);
	void print(int width, int align, char *str);

	void printf(char *fmt, ...);
	void printf(int width, int align, char *fmt, ...);

	int getTextWidth(char *str);
	int getTextHeight(char *str);
};

#endif //_FONT_PIX_H_